﻿using System;
using System.Collections;
using System.IO;
using System.Text;
using UnityEngine;

// Token: 0x020005E2 RID: 1506
public class BaseLoader : MonoBehaviour
{
	// Token: 0x06002405 RID: 9221 RVA: 0x0013DEBC File Offset: 0x0013C0BC
	protected virtual void Awake()
	{
		this.Initialize();
		if (this.isErase)
		{
			UnityEngine.Object.Destroy(base.gameObject);
		}
	}

	// Token: 0x06002406 RID: 9222 RVA: 0x0013DEDC File Offset: 0x0013C0DC
	public virtual void Initialize()
	{
		if (global::Singleton<global::AssetBundleManager>.IsInstance())
		{
			return;
		}
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(Application.dataPath);
		stringBuilder.Append(global::BaseLoader.DATA_PATH);
		global::AssetBundleManager.Initialize("abdata", stringBuilder.ToString());
	}

	// Token: 0x06002407 RID: 9223 RVA: 0x0013DF24 File Offset: 0x0013C124
	public virtual string GetRelativePath()
	{
		if (Application.isEditor)
		{
			return "file://" + Environment.CurrentDirectory.Replace("\\", "/");
		}
		if (Application.isWebPlayer)
		{
			return Path.GetDirectoryName(Application.absoluteURL).Replace("\\", "/") + "/StreamingAssets";
		}
		if (Application.isMobilePlatform || Application.isConsolePlatform)
		{
			return Application.streamingAssetsPath;
		}
		return "file://" + Application.streamingAssetsPath;
	}

	// Token: 0x06002408 RID: 9224 RVA: 0x0013DFB4 File Offset: 0x0013C1B4
	private static string GetPlatformFolderForAssetBundles(RuntimePlatform platform)
	{
		switch (platform)
		{
		case RuntimePlatform.IPhonePlayer:
			return "iOS";
		default:
			if (platform == RuntimePlatform.OSXPlayer)
			{
				return "OSX";
			}
			if (platform != RuntimePlatform.WindowsPlayer)
			{
				return null;
			}
			return "Windows";
		case RuntimePlatform.Android:
			return "Android";
		}
	}

	// Token: 0x06002409 RID: 9225 RVA: 0x0013E008 File Offset: 0x0013C208
	public virtual T Load<T>(string assetBundleName, string assetName, bool isClone = false, bool isCloneRename = false, string manifestAssetBundleName = null) where T : UnityEngine.Object
	{
		global::AssetBundleLoadAssetOperation assetBundleLoadAssetOperation = global::AssetBundleManager.LoadAsset(assetBundleName, assetName, typeof(T), manifestAssetBundleName);
		T t = assetBundleLoadAssetOperation.GetAsset<T>();
		if (!(t != null))
		{
			global::Debug.LogError(assetName + " isn't loaded successfully");
		}
		if (isClone)
		{
			T t2 = UnityEngine.Object.Instantiate<T>(t);
			if (isCloneRename)
			{
				t2.name = t.name;
			}
			t = t2;
		}
		return t;
	}

	// Token: 0x0600240A RID: 9226 RVA: 0x0013E088 File Offset: 0x0013C288
	public virtual IEnumerator Load_Coroutine<T>(string assetBundleName, string assetName, Action<T> act = null, bool isClone = false, bool isCloneRename = false, string manifestAssetBundleName = null) where T : UnityEngine.Object
	{
		global::AssetBundleLoadAssetOperation request = global::AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(T), manifestAssetBundleName);
		if (request == null)
		{
			yield break;
		}
		yield return base.StartCoroutine(request);
		T asset = request.GetAsset<T>();
		if (asset != null)
		{
		}
		if (isClone)
		{
			T clone = UnityEngine.Object.Instantiate<T>(asset);
			if (isCloneRename)
			{
				clone.name = asset.name;
			}
			asset = clone;
		}
		if (!act.IsNullOrEmpty())
		{
			act(asset);
		}
		yield break;
	}

	// Token: 0x0600240B RID: 9227 RVA: 0x0013E100 File Offset: 0x0013C300
	public virtual T[] LoadAll<T>(string assetBundleName, bool isClone = false, bool isCloneRename = false, string manifestAssetBundleName = null) where T : UnityEngine.Object
	{
		global::AssetBundleLoadAssetOperation assetBundleLoadAssetOperation = global::AssetBundleManager.LoadAllAsset(assetBundleName, typeof(T), manifestAssetBundleName);
		T[] allAssets = assetBundleLoadAssetOperation.GetAllAssets<T>();
		if (allAssets != null)
		{
			global::Debug.Log(assetBundleName + " is loaded successfully at frame " + Time.frameCount);
		}
		else
		{
			global::Debug.LogError(assetBundleName + " isn't loaded successfully");
		}
		if (isClone)
		{
			for (int i = 0; i < allAssets.Length; i++)
			{
				T t = UnityEngine.Object.Instantiate<T>(allAssets[i]);
				if (isCloneRename)
				{
					t.name = allAssets[i].name;
				}
				allAssets[i] = t;
			}
		}
		return allAssets;
	}

	// Token: 0x0600240C RID: 9228 RVA: 0x0013E1B4 File Offset: 0x0013C3B4
	public virtual IEnumerator LoadAll_Coroutine<T>(string assetBundleName, Action<T[]> act = null, bool isClone = false, bool isCloneRename = false, string manifestAssetBundleName = null) where T : UnityEngine.Object
	{
		global::Debug.Log(string.Concat(new object[]
		{
			"Start to load all",
			assetBundleName,
			" at frame ",
			Time.frameCount
		}));
		global::AssetBundleLoadAssetOperation request = global::AssetBundleManager.LoadAllAssetAsync(assetBundleName, typeof(T), manifestAssetBundleName);
		if (request == null)
		{
			yield break;
		}
		yield return base.StartCoroutine(request);
		T[] asset = request.GetAllAssets<T>();
		if (asset != null)
		{
			global::Debug.Log(assetBundleName + " is loaded successfully at frame " + Time.frameCount);
		}
		else
		{
			global::Debug.LogError(assetBundleName + " isn't loaded successfully");
		}
		if (isClone)
		{
			for (int i = 0; i < asset.Length; i++)
			{
				T clone = UnityEngine.Object.Instantiate<T>(asset[i]);
				if (isCloneRename)
				{
					clone.name = asset[i].name;
				}
				asset[i] = clone;
			}
		}
		if (!act.IsNullOrEmpty())
		{
			act(asset);
		}
		yield break;
	}

	// Token: 0x0600240D RID: 9229 RVA: 0x0013E21C File Offset: 0x0013C41C
	public virtual void LoadLevel(string assetBundleName, string levelName, bool isAdditive, string manifestAssetBundleName = null)
	{
		global::AssetBundleManager.LoadLevel(assetBundleName, levelName, isAdditive, manifestAssetBundleName);
		global::Debug.Log(string.Concat(new object[]
		{
			"Finish loading scene ",
			levelName,
			" at frame ",
			Time.frameCount
		}));
	}

	// Token: 0x0600240E RID: 9230 RVA: 0x0013E25C File Offset: 0x0013C45C
	public virtual IEnumerator LoadLevel_Coroutine(string assetBundleName, string levelName, bool isAdditive, string manifestAssetBundleName = null)
	{
		global::Debug.Log(string.Concat(new object[]
		{
			"Start to load scene ",
			levelName,
			" at frame ",
			Time.frameCount
		}));
		global::AssetBundleLoadOperation request = global::AssetBundleManager.LoadLevelAsync(assetBundleName, levelName, isAdditive, manifestAssetBundleName);
		if (request == null)
		{
			yield break;
		}
		yield return base.StartCoroutine(request);
		global::Debug.Log(string.Concat(new object[]
		{
			"Finish loading scene ",
			levelName,
			" at frame ",
			Time.frameCount
		}));
		yield break;
	}

	// Token: 0x04002C19 RID: 11289
	public const string BASE_BUNDLE_FOLDER = "abdata";

	// Token: 0x04002C1A RID: 11290
	public const string LocalPath = "file://";

	// Token: 0x04002C1B RID: 11291
	public const string NetWorkPath = "http://";

	// Token: 0x04002C1C RID: 11292
	[SerializeField]
	protected bool isErase;

	// Token: 0x04002C1D RID: 11293
	protected static string DATA_PATH = "/../abdata" + '/';
}
